package com.atguigu.gmall.juc.atomic;

/**
 * @author 陈昆昆
 * @version 1.0
 * @date 2020/6/3 11:14
 */
public class Stack {
    private static Object resources1 = new Object();
    private static Object resources2 = new Object();

    public static void main(String[] args) {
        new Thread(()->{
            synchronized (resources1){
                System.out.println(Thread.currentThread() + "获得resources1");
                try {
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (resources2){
                    System.out.println(Thread.currentThread()+"尝试获取resources2");
                }
            }
        },"thread1").start();

        new Thread(()->{
            synchronized (resources2){
                System.out.println(Thread.currentThread() + "获得resources1");
                try {
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (resources1){
                    System.out.println(Thread.currentThread()+"尝试获取resources2");
                }
            }
        },"thread2").start();
    }
}
